var ClubShowRoomUnit = Unit.extend({
    _ccsFileName: res.ClubShowRoomUnit_json,
    initUnit: function () {

    },
    /**
     * View基类初始化
     */
    initView: function () {
        this._actionType = ViewActionType.None;
        if (this._actionType === ViewActionType.None) {
            this._rootNode.show();
        }
        this._loadCCSFinished = true;
        this.setData.apply(this, arguments);
    },
    onEnter: function () {
        Unit.prototype.onEnter.call(this);
        this._initAllListeners();
    },
    _initClickListeners: function () {
        this._clickListeners = {
            //'bg1': '_clickBg',
            'btn_quitRoom': '_clickQuitRoom',
            'btn_backRoom': '_clickBackRoom',
        }
    },
    /**
     * 监听亲友圈消息
     * @private
     */
    _initEventListeners: function () {
        this._eventListeners = {};
        this._eventListeners[ClubEvent.ClubShowRoomUnitRefresh] = 'refreshView';
    },


    _clickBg: function () {

    },

    _clickQuitRoom: function () {
        clubMsgManager.requestQuitRoom('确定要退出房间吗?');
    },

    _clickBackRoom: function () {
        eventManager.dispatchEvent(ClubEvent.ClubTableWindowClose);
    },

    refreshView: function () {
        this._nodeList['lb_roomId'].setString('房间号:' + gameData.roomId);
        this._nodeList['lb_person'].setString(gameData.players.length + '/' + gameData.playerNum);

        var scrollView = this._nodeList['playerView'];
        var cell0 = this._nodeList['user0'];
        cell0.setVisible(false);
        if (gameData.players) {
            var viewHight = 50 * gameData.players.length;
            scrollView.removeAllChildren();

            var innerHeight = scrollView.getContentSize().height;
            if (viewHight >= innerHeight) {
                innerHeight = viewHight;
            }
            scrollView.innerHeight = innerHeight;
            scrollView.setInnerContainerSize(cc.size(230, viewHight));
            for (var i = 0; i < gameData.players.length; i++) {
                var cell = scrollView.getChildByName('cell' + i);
                if (!cell) {
                    cell = duplicateNode(cell0);
                    cell.setName('cell' + i);
                    cell.setVisible(true);
                    scrollView.addChild(cell);
                }
                cell.setPosition(cc.p(0, innerHeight - 50 * i - 50));
                this._refreshCell(cell, i);
            }
        }
    },

    _refreshCell: function (cell, i) {
        cell.getChildByName('lb_name').setString(ellipsisStr((gameData.players[i].NickName || gameData.players[i].nickname), 5));
        if (gameData.players[i]['ready'] && gameData.players[i]['ready'] == 1) {
            cell.getChildByName('lb_ready').setString('已准备');
            cell.getChildByName('lb_ready').setTextColor(cc.color(17, 172, 38));
        } else {
            cell.getChildByName('lb_ready').setString('未准备');
            cell.getChildByName('lb_ready').setTextColor(cc.color(220, 20, 25));
        }
    },
});